#include "RingQueue.hpp"

void* Producertask(void* arg)
{
    RingQueue<int>* q = (RingQueue<int>*)arg;
    //生产者生产数据
    while(1)
    {
        sleep(1);
        int data = rand()%100+1;
        q->Push(data);
        std::cout << "producer : " << data << std::endl;
    }
}

void* Comsumertask(void* arg)
{
    RingQueue<int>* q = (RingQueue<int>*)arg;
    while(1)
    {
        sleep(1);
        int data = 0;
        q->Pop(data);
        std::cout << "comsumer : " << data << std::endl;
    }
}

int main()
{
    //生成随机数
    srand((unsigned int)time(nullptr));

    pthread_t producer, comsumer;
    RingQueue<int>* q = new RingQueue<int>;
    //创建两个新线程
    pthread_create(&producer, NULL, Producertask, q);
    pthread_create(&comsumer, NULL, Comsumertask, q);

    pthread_join(producer, NULL);
    pthread_join(comsumer, NULL);
    delete q;

    return 0;
}